//
//  SSSpecTableViewCell.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/2/27.
//

import UIKit

typealias IndexPathClosure = (_ indexPath: IndexPath) ->Void

class SSSpecTableViewCell: UITableViewCell {
    
    var isfeeHiden = false
    

    @IBOutlet weak var feeLab: UILabel!
    @IBOutlet weak var descLab: UILabel!
    @IBOutlet weak var selectBtn: UIButton!
    
    var indexPathClosure: IndexPathClosure?
    var indexPath: IndexPath?
  
    
    override func awakeFromNib() {
        super.awakeFromNib()
        selectionStyle = .none
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    @IBAction func btnAction(_ sender: Any) {
//        let btn = sender as! UIButton
        let btn = selectBtn!
//        btn.isSelected = !btn.isSelected
        if btn.isSelected {
            return
        }
        if self.indexPathClosure != nil {
            self.indexPathClosure!(self.indexPath!)
        }
    }
    
    func setData(data:SSSpec) {
        feeLab.isHidden = isfeeHiden
        feeLab.text = "+$\(data.fee)"
        descLab.text = data.name
    }
    
    func setChecked(isselected:Bool) {
        selectBtn.isSelected = isselected
    }
    
    func getIndexWithClosure(closure: IndexPathClosure?) {
        self.indexPathClosure = closure
    }
    
}
